package com.gyul.findmystock.ui.stock;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v13.app.FragmentTabHost;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gyul.findmystock.R;
import com.gyul.findmystock.entity.CompanyEntity;
import com.gyul.findmystock.util.Constants;
import com.gyul.findmystock.util.Utils;

public class StockActivity extends Activity {
	private FragmentTabHost mTabHost;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// requestWindowFeature(Window.FEATURE_NO_TITLE |
		// Window.FEATURE_ACTION_BAR);
		setContentView(R.layout.activity_stock);

		final ActionBar actionBar = getActionBar();
		CompanyEntity company = (CompanyEntity)getIntent().getSerializableExtra(Constants.COMPANY_EXTRA);
		actionBar.setTitle(company.name);

		mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this, getFragmentManager(), R.id.stock_tabcontent);

		String title = Utils.getResourceString(R.string.title_stock_price);
		mTabHost.addTab(mTabHost.newTabSpec(title).setIndicator(title),
				FragmentStockPrice.class, null);

		title = Utils.getResourceString(R.string.title_stock_chart);
		mTabHost.addTab(mTabHost.newTabSpec(title).setIndicator(title),
				FragmentStockChart.class, null);

		title = Utils.getResourceString(R.string.title_stock_analysis);
		mTabHost.addTab(mTabHost.newTabSpec(title).setIndicator(title),
				FragmentStockAnalysis.class, null);

		int tabCount = mTabHost.getTabWidget().getTabCount();
		for (int i = 0; i < tabCount; i++) {
			final View view = mTabHost.getTabWidget().getChildTabViewAt(i);
			if (view != null) {
				// reduce height of the tab

				// get title text view
				final View textView = view.findViewById(android.R.id.title);
				if (textView instanceof TextView) {
					// just in case check the type

					// center text
					((TextView) textView).setGravity(Gravity.CENTER);
					// wrap text
					((TextView) textView).setSingleLine(false);
//					((TextView) textView).setBackgroundColor(Color.GREEN);

					// explicitly set layout parameters
					textView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
					textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
				}
			}
		}
	}
}